<template>
  <div o-Container>
    <div class="content_left_box">
      <div class="top_box">
        <div class="button_box">
          <button @click="ShowCreationDialog()">
            {{ !addRightsShow ? "创作精品礼包" : "创作精品权益" }}
          </button>
        </div>
      </div>
    </div>
    <o-list v-bind:source="list.contract">
      <template slot="config" slot-scope="scope">
        <div class="img_box">
          <img @click="look(scope)" src="/static/skin/default/MCS/AIGC/Inventory/images/chakan.png" alt="" />
          <img @click="edit(scope)" src="/static/skin/default/MCS/AIGC/Inventory/images/bianji.png" alt="" />
          <img @click="del(scope)" src="/static/skin/default/MCS/AIGC/Inventory/images/shanchu.png" alt="" />
        </div>
      </template>
    </o-list>
    <addOrdering ref="addOrdering" :isEdit="isEdit" @createdSuccess="reload"></addOrdering>
    <creationDialog @createdSuccess="reload" ref="creationDialog" :isEdit="isEdit"></creationDialog>
  </div>
</template>

<script>
import creationDialog from "../../MyRightsComponents/creationDialog.vue";
import addOrdering from "../../MyRightsComponents/addOrdering.vue";
export default {
  name: "mms_platform_company_list" /* 草稿库-单个权益库 */,
  components: {
    creationDialog,
    addOrdering
  },
  // provide(){
  //   return {
  //     isEdit:this.isEdit
  //   }
  // },
  data() {
    return {
      octopus: this.$parent.octopus,
      list: {
        contract: {
          data: {
            id: 1374, // 菜单表的八爪鱼ID
            cellData: [
              { name: "ProjectID" , show: false},	// ProjectID
              { name: "Name", width: 350 }, // 权益标题
              { name: "TypeID", show: false, filterKey: "=", filterValue: "" }, // 权益类型
              { name: "Status" }, // 权益状态
              { name: "InventoryQuantity" }, // 库存数量(份)
              { name: "SalePrice" }, // 市场价格(元)
              { name: "CostPrice" }, // 平台价格(元)
              { name: "PlatformServiceRate" }, // 权益平台服务费
              { name: "EquityServiceRate" }, // 小程序服务费
              { name: "Integral" }, // 让利积分
              { name: "UpdateTime" }, // 操作时间
              // { name: "CompanyID" },	// 公司
              // { name: "ContractID" },	// 合同编号
              // { name: "CreateTime" },	// 权益创建时间
              // { name: "CreateUserID" },	// 权益创建人
              // { name: "EffectiveTime" },	// 过期时间
              { name: "EquityFlagList", show: false }, // 权益标签
              { name: "EquityFlagListName" }, // 权益标签
              // { name: "ExpireTime" },	// 过期时间
              // { name: "ID" },	// 权益ID
              { name: "MainPicturePath" }, // 主图
              { name: "MinimumQuantity", show: false }, // 起购数量
              // { name: "ProductFlagList" },	// 产品标签
              // { name: "ProductFlagListName" },	// 产品标签中文
              { name: "SecondaryPicturePath" }, // 副图
              // { name: "SoldQuantity" },	// 已售
              { name: "TransferRuleID", show: false }, // 采购公司限制
              { name: "TransferRuleIDName" }, // 采购公司限制
              { name: "IsOpenSale", show: false }, // IsOpenSale
              { name: "IsRefund", show: false }, // IsRefund
              { name: "Description", show: false }, // 使用规则
              { name: "UseRuleDescription", show: false } // 子权益
            ],
            paramData: {
              CompanyID: "NULL", //公司ID
              Status: '1,4', // 1 草稿箱 1,4
              TypeID: 1, // 1 个人权益， 2 组合权益
              FlagList: "NULL"
            }
          },
          configWidth: 90,
          showNumber: true
        }
      },
      isEdit: true,
      addRightsShow: false
    };
  },
  mounted() { },
  created() {
    this.list.contract.data.paramData.CompanyID = this.octopus.passport.authorization.company;

    let url = this.octopus.vue.$route.path;
    // 创建权益时判断是否为组合权益
    if (url == "/MMS/AIGC/Draft/SingleRights/List") {
      this.addRightsShow = true;
      this.list.contract.data.paramData.TypeID = 1;
      this.list.contract.data.cellData[1].filterValue = 1;
    } else {
      this.addRightsShow = false;
      this.list.contract.data.paramData.TypeID = 2;
      this.list.contract.data.cellData[1].filterValue = 2;
    }
  },
  methods: {
    load() {
      this.list.contract.control.load();
    },
    ShowCreationDialog() {
      if (!this.addRightsShow) {
        this.isEdit = false;
        this.$refs.addOrdering.drawerOp();
      } else {
        this.isEdit = false;
        this.$refs.creationDialog.drawerOp();
      }
    },
    look(row) {
      this.isEdit = true;
      if (!this.addRightsShow) {
        this.$refs.addOrdering.drawerOp(row.data, "look", true);
      } else {
        this.$refs.creationDialog.drawerOp(row.data, "look");
      }
    },
    edit(row) {
      this.isEdit = false;
      if (!this.addRightsShow) {
        this.$refs.addOrdering.drawerOp(row.data, "UPDATE", true);
      } else {
        this.$refs.creationDialog.drawerOp(row.data, "UPDATE");
      }
    },
    del(row) {
      this.$confirm(`是否删除这个草稿?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(res => {
          res == "confirm" && this.delItem(row.data);
        })
        .catch(() => {
          console.log("取消了");
        });
    },
    delItem(data) {
      this.octopus.tools.openAPI(
        `/ESB/AIGC/deleteEquity?id=${data.row.ID}`,
        {},
        datas => {
          if (datas.content.status.code == 200) {
            this.list.contract.control.load();
            this.$message({
              message: "删除成功。",
              type: "success"
            });
          } else {
            this.octopus.tips.error(datas);
          }
        }
      );
    },

    reload() {
      this.list.contract.control.load();
    }
  },
  props: ["oData"]
};
</script>
<style scoped>
@import "../../../../../../static/skin/default/MMS/AIGC/css/base.css";

.content_left_box {
  padding-bottom: 0;
}

.img_box {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.img_box img {
  width: 25px;
  cursor: pointer;
}

>>>.Content {
  height: 84vh !important;
}
</style>
